package com.lq.educationsystem.admin.controller;

import com.lq.educationsystem.admin.entiy.AdminTb;
import com.lq.educationsystem.admin.service.AdminBaseService;
import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.vo.AdminPageVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "管理员基础")
@RequestMapping("/admin/base")
@RestController
public class AdminBaseController {
    //Service服务
    @Autowired
    AdminBaseService adminBaseService;

    //通过id查询用户信息

    @Operation(summary = "通过id查询信息")
    @PostMapping("/querybyid/{adminId}")
    public Result queryById(@PathVariable("adminId") int adminId){

        //调用服务
        Result adminInfo= adminBaseService.queryAdminById(adminId);

        //返回结果
        return adminInfo;

    }

    //新增用户信息
    @Operation(summary = "新增管理员信息")
    @PostMapping("/insert")
    public Result insertAdmin(@RequestBody AdminTb adminTb){
        //调用服务

        adminBaseService.insertAdmin(adminTb);
        //返回结果

        return ResultBuild.buildOk();

    }

    //更新信息
    @Operation(summary = "更新管理员信息")
    @PostMapping("/update")
    public Result updateAdminInfo(@RequestBody AdminTb adminTb) {
        System.out.println("传入的数据为:"+adminTb);
        //调用跟新用户信息
        adminBaseService.updateAdminInfo(adminTb);
        //返回结果
        return ResultBuild.buildOk();
    }

    //删除信息
    @Operation(summary = "删除管理源信息")
    @PostMapping("/delete")
    public Result deleteAdminInfo(@RequestBody AdminTb adminTb) {
        //删除用户信息
        adminBaseService.deleteAdminInfo(adminTb);

        return ResultBuild.buildOk();
    }

    //查询信息
    @Operation(summary = "查询管理员信息")
    @PostMapping("/query")
    public ResultPage<AdminTb> queryList(@RequestBody AdminPageVo adminPageVo){
        //查询数据
        ResultPage<AdminTb> adminTbResultPage= adminBaseService.queryList(adminPageVo);

        //拿到结果返回
        return adminTbResultPage;

    }
}
